<?php
define('DEFAULT_ROLE', 'guest');

class System_App_Auth extends System_App_Noyau{
    private $connected_user;
    
    function __construct(){
        $this->register('auth');
        $this->connected_user = $this->checkConnectedUser();
        
    }
    
    private function checkConnectedUser(){
        
        if( isset($_SESSION['user_log']) && $_SESSION['user_log'] === true ){
            return new Model_User( $_SESSION['user_id'] );
        }else{
            return null;
        }
    }
    
    public function is_connected(){
        if( $this->connected_user !== null ){
            return true;
        }else{
            return false;
        }
    }
    
    public function getUser(){
        return $this->connected_user;
    }
    
    public function getRole(){
         return ($this->connected_user !== null)?$this->connected_user->getRole():DEFAULT_ROLE;
    }
}

?>
